﻿using System;
using System.Windows.Forms;
using Paragon;
using Paragon.Core;

namespace ParagonUI
{
    public partial class Display : Form
    {
        public ParagonEngine Engine { get; set; }
        
        public Display()
        {
            InitializeComponent();

            Engine = new ParagonEngine(this.CreateGraphics());
        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            Engine.Start();
            
            btnStart.Enabled = false;
        }

        private void btnStop_Click(object sender, EventArgs e)
        {
            Engine.Stop();

            btnStart.Enabled = true;
        }

        private void Display_FormClosing(object sender, FormClosingEventArgs e)
        {
            Engine.Stop();
        }

        private void Display_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Add)
            {
                Engine.MoveState = MovementState.Forward;
            }
            else if (e.KeyCode == Keys.Subtract)
            {
                Engine.MoveState = MovementState.Back;
            }
            else if (e.KeyCode == Keys.None)
            {
                Engine.MoveState = MovementState.Idle;
            }
        }

        private void Display_KeyUp(object sender, KeyEventArgs e)
        {
            Engine.MoveState = MovementState.Idle;
        }
    }
}